<template>
  <div class="user-dynamic-page">
    <van-nav-bar
      title="我的动态"
      left-arrow
      @click-left="onClickLeft"
      fixed
      placeholder
    />
    
    <div class="page-content">
      <my-dynamic-list :user-id="userId" />
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, computed } from 'vue';
import { useRouter } from 'vue-router';
import { getCurrentUser } from '../services/user';
import MyDynamicList from '../components/MyDynamicList.vue';

const router = useRouter();
const currentUser = ref(null);
const userId = computed(() => currentUser.value?.userId || null);

onMounted(async () => {
  try {
    // 获取当前登录用户信息
    const userInfo = await getCurrentUser();
    if (userInfo) {
      currentUser.value = userInfo;
    } else {
      router.push('/user/login');
    }
  } catch (error) {
    console.error('获取用户信息失败', error);
  }
});

// 返回上一页
const onClickLeft = () => {
  router.back();
};
</script>

<style scoped>
.user-dynamic-page {
  background-color: #f7f8fa;
  min-height: 100vh;
}

.page-content {
  padding: 8px 0;
}
</style> 